<?php
declare(strict_types=1);

namespace LowCode\Naive;

use LowCode\Naive;
use LowCode\Support\JsExp;
use LowCode\Traits\Events\HasOnClose;
use LowCode\Traits\Props\HasBordered;
use LowCode\Traits\Props\HasCheckAble;
use LowCode\Traits\Props\HasChecked;
use LowCode\Traits\Props\HasClosable;
use LowCode\Traits\Props\HasDisabled;
use LowCode\Traits\Props\HasRound;
use LowCode\Traits\Props\HasSize;
use LowCode\Traits\Props\HasStrong;
use LowCode\Traits\Props\HasType;
use LowCode\Traits\Slots\HasSlotAvatar;
use LowCode\Traits\Slots\HasSlotIcon;

/**
 * 组件 - 标签 Tag
 * @method static Tag make(mixed $children = null) Tag组件
 */
class Tag extends Naive
{

    use HasClosable, HasDisabled, HasBordered, HasSize, HasRound, HasChecked, HasCheckAble, HasStrong, HasType;

    use HasSlotAvatar, HasSlotIcon;

    use HasOnClose;

    /**
     * @param mixed|null $children
     */
    public function __construct(mixed $children = null)
    {
        parent::__construct();
        $children && $this->children($children);
    }

    /**
     * 标签类型
     * @param string|JsExp $type 'default' | 'primary' | 'info' | 'success' | 'warning' | 'error'
     * @return $this
     */
    public function type(string|JsExp $type = 'default' | 'primary' | 'info' | 'success' | 'warning' | 'error'): static
    {
        return $this->prop('type',$type);
    }

    /**
     * 默认标签类型
     * @return $this
     */
    public function default(): static
    {
        return $this->type('default');
    }

    /**
     * 关闭时是否触发点击事件
     * @param bool|JsExp $bool
     * @return $this
     */
    public function triggerClickOnClose(bool|JsExp $bool = true): static
    {
        return $this->prop('triggerClickOnClose', $bool);
    }

    /**
     * 标签颜色，设置该项后　type 无效
     * @param array|JsExp $value { color?: string, borderColor?: string, textColor?: string }
     * @return $this
     */
    public function color(array|JsExp $value = ["color"=>"blue","borderColor"=>"red","textColor"=>"red"]): static
    {
        return $this->prop("color",$value);
    }

    /**
     * onUpdateChecked 选择状态更改时的回调
     * @param string $event 函数 (value: boolean) => void
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onUpdateChecked(string $event = "(value)=>{}", string $id = null, array $modifiers = []): static
    {
        return $this->event("update:checked", jsFn($event,$id), $modifiers);
    }

}
